package com.doge.walknovel.api

import com.doge.walknovel.analysis.AppsFlyerHelper
import com.doge.walknovel.api.model.*
import com.doge.walknovel.business.login.PROFILE_TYPE_FACEBOOK
import com.doge.walknovel.business.login.PROFILE_TYPE_GOOGLE
import com.doge.walknovel.utils.*
import io.reactivex.Observable
import retrofit2.http.*

interface ApiService {
    @POST("api/signOut")
    fun signOut(): Observable<ApiResult<Any?>>

    @FormUrlEncoded
    @POST("api/register/thirdParty")
    fun loginByGoogle(
        @Field("account") account: String?,
        @Field("thirdPartyToken") thirdPartyToken: String?,
        @Field("nickName") nickName: String?,
        @Field("profilePicture") profilePicture: String?,
        @Field("country") country: String = language.country,
        @Field("deviceNo") deviceNo: String = DeviceUtils.deviceId,
        @Field("systemModel") systemModel: String = android.os.Build.MODEL,
        @Field("thirdPartyType") thirdPartyType: Int = PROFILE_TYPE_GOOGLE, // 1facebook 2google 4apple 5russia_vk
        @Field("afStatus") afStatus: String? = AppsFlyerHelper.afStatus,
        @Field("origCost") origCost: String? = AppsFlyerHelper.origCost,
        @Field("installReferrer") installReferrer: String? = InstallReferUtils.referrer,
    ): Observable<ApiResult<LoginTokenInfo>>

    @FormUrlEncoded
    @POST("api/register/thirdParty")
    fun loginByFacebook(
        @Field("account") account: String?,
        @Field("thirdPartyToken") thirdPartyToken: String?,
        @Field("nickName") nickName: String?,
        @Field("profilePicture") profilePicture: String?,
        @Field("country") country: String = language.country,
        @Field("deviceNo") deviceNo: String = DeviceUtils.deviceId,
        @Field("systemModel") systemModel: String = android.os.Build.MODEL,
        @Field("thirdPartyType") thirdPartyType: Int = PROFILE_TYPE_FACEBOOK, // 1facebook 2google 4apple 5russia_vk
        @Field("afStatus") afStatus: String? = AppsFlyerHelper.afStatus,
        @Field("origCost") origCost: String? = AppsFlyerHelper.origCost,
        @Field("installReferrer") installReferrer: String? = InstallReferUtils.referrer,
    ): Observable<ApiResult<LoginTokenInfo>>


    @POST("api/member/personalDetail")
    fun userInfo(): Observable<ApiResult<UserInfo>>

    @GET("api/advertise/list")
    fun adList(@Query("location") location: Int): Observable<ApiResult<List<BannerInfo>>>

    @POST("api/novel/homePage")
    fun novelHomePage(): Observable<ApiResult<List<StrategyInfo>>>

    @FormUrlEncoded
    @POST("api/novel/viewMore")
    fun novelViewMore(
        @Field("titleId") titleId: Int,
        @Field("tabId") tabId: Int?,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE
    ): Observable<ApiResult<List<NovelInfo>>>

    @FormUrlEncoded
    @POST("api/novel/detail")
    fun novelDetail(@Field("novelId") novelId: Int,
                    @Field("refer") refer: String,
                    @Field("referId") referId: Int?,
    ): Observable<ApiResult<NovelDetailInfo>>

    @FormUrlEncoded
    @POST("api/bookshelf/saveNovel")
    fun novelSave(@Field("novelId") novelId: Int): Observable<ApiResult<Any?>>

    @FormUrlEncoded
    @POST("api/bookshelf/removeNovel")
    fun novelRemove(@Field("novelId") novelId: Int): Observable<ApiResult<Any?>>

    @GET("api/bookshelf/novelList")
    fun novelMyLib(
        @Query("pageNo") pageNo: Int = 0,
        @Query("pageSize") pageSize: Int = Int.MAX_VALUE - 1
    ): Observable<ApiResult<List<NovelInfo>>>

    /** targetType 1小说、2章节、3评论 */
    @FormUrlEncoded
    @POST("api/novel/commentList")
    fun novelCommentList(
        @Field("targetId") novelId: Int,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE,
        @Field("targetType") targetType: Int = 1,
    ): Observable<ApiResult<List<CommentInfo>>>

//    /** targetType 1小说、2章节、3评论 */
//    @FormUrlEncoded
//    @POST("api/novel/commentList")
//    fun novelChapterCommentList(
//        @Field("targetId") chapterId: Int,
//        @Field("pageNo") pageNo: Int,
//        @Field("pageSize") pageSize: Int = PAGE_SIZE,
//        @Field("targetType") targetType: Int = 2
//    ): Observable<ApiResult<List<CommentInfo>>>

    /** targetType 1小说、2章节、3评论 */
    @FormUrlEncoded
    @POST("api/novel/commentList")
    fun novelReplyList(
        @Field("targetId") commentId: Int,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE,
        @Field("targetType") targetType: Int = 3
    ): Observable<ApiResult<List<CommentInfo>>>

    @FormUrlEncoded
    @POST("api/novel/chapterList")
    fun novelChapterList(
        @Field("novelId") novelId: Int,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = chapterPageSize
    ): Observable<ApiResult<List<ChapterInfo>>>

    @FormUrlEncoded
    @POST("api/novel/getChapterContent")
    fun novelChapterContent(@Field("chapterId") chapterId: Int): Observable<ApiResult<ChapterInfo>>

    @FormUrlEncoded
    @POST("api/novel/unLockChapter")
    fun novelChapterUnlock(@Field("chapterId") chapterId: Int): Observable<ApiResult<ChapterInfo>>

    @FormUrlEncoded
    @POST("api/novel/getChapterByProgress")
    fun novelChapterInfoByProgress(
        @Field("novelId") novelId: Int,
        @Field("progress") progress: Float
    ): Observable<ApiResult<ChapterInfo>>

    @FormUrlEncoded
    @POST("api/novel/recordReadChapter")
    fun novelChapterRecordRead(@Field("chapterId") chapterId: Int): Observable<ApiResult<Any?>>

    /** targetType 1小说、2章节、3评论 */
    @FormUrlEncoded
    @POST("api/novel/submitComment")
    fun novelSubmitComment(
        @Field("targetId") novelId: Int,
        @Field("content") content: String,
        @Field("score") score: Int?,
        @Field("targetType") targetType: Int
    ): Observable<ApiResult<CommentInfo>>

    @FormUrlEncoded
    @POST("api/novel/likeComment")
    fun novelLikeComment(@Field("commentId") commentId: Int): Observable<ApiResult<Any?>>

    @FormUrlEncoded
    @POST("api/novel/unLikeComment")
    fun novelUnLikeComment(@Field("commentId") commentId: Int): Observable<ApiResult<Any?>>

    @FormUrlEncoded
    @POST("api/novel/search")
    fun novelSearch(
        @Field("keyword") keyword: String,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE
    ): Observable<ApiResult<List<NovelInfo>>>

    @FormUrlEncoded
    @POST("api/novel/viewHistory")
    fun novelViewedHistory(
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE
    ): Observable<ApiResult<List<NovelInfo>>>

    @GET("api/novel/getRankTabs")
    fun novelGetRankTabs(): Observable<ApiResult<List<StrategyChildInfo>>>

    @GET("api/novel/getGenresTabs")
    fun novelGetGenresTabs(): Observable<ApiResult<List<StrategyChildInfo>>>

    @FormUrlEncoded
    @POST("api/novel/genresRankList")
    fun novelGenresRankList(
        @Field("tagId") tagId: Int,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE
    ): Observable<ApiResult<List<NovelInfo>>>

    @FormUrlEncoded
    @POST("api/novel/genresGenresList")
    fun novelGenresGenresList(
        @Field("tagId") tagId: Int,
        @Field("pageNo") pageNo: Int,
        @Field("pageSize") pageSize: Int = PAGE_SIZE
    ): Observable<ApiResult<List<NovelInfo>>>

    @FormUrlEncoded
    @POST("api/push/updateToken")
    fun pushUpdateToken(@Field("pushToken") pushToken: String,
        @Field("deviceNo") deviceNo: String = DeviceUtils.deviceId): Observable<ApiResult<Any?>>

    @GET("api/push/pushEnableList")
    fun pushEnableList(): Observable<ApiResult<PushEnableInfo>>

    @FormUrlEncoded
    @POST("api/push/management")
    fun pushManagement(
        @Field("chapterUpdatePush") chapterUpdatePush: Int?,
        @Field("activityPush") activityPush: Int?
    ): Observable<ApiResult<Any?>>
    @GET("api/recharge/walletDetail")
    fun rechargeWalletDetail(
        @Query("pageNo") pageNo: Int = 1,
        @Query("pageSize") pageSize: Int = 30
    ): Observable<ApiResult<List<WalletDetailInfo>>>

    @GET("api/recharge/getGoogleSkuList")
    fun rechargeGoogleSkuList(): Observable<ApiResult<RechargeGoogleSkuInfo>>

    @GET("api/recharge/rechargeRuleList/v2")
    fun rechargeRuleListV2(): Observable<ApiResult<TopUpInfo>>

    @FormUrlEncoded
    @POST("api/recharge/googleCallback")
    fun rechargeGoogleCallback(
        @Field("signature") signature: String,
        @Field("purchaseinfo") purchaseinfo: String,
        @Field("transactionid") transactionid: String,
        @Field("productid") productid: String,
        @Field("remark") remark: String,
        @Field("refer") refer: String
    ): Observable<ApiResult<Any?>>

    @GET("api/version/info")
    fun versionInfo(): Observable<ApiResult<VersionInfo>>

//    @GET("api/version/asyncResList")
//    fun versionAsyncResList(): Observable<ApiResult<List<AsyncResInfo>>>

    @FormUrlEncoded
    @POST("api/feedback/report")
    fun feedback(
        @Field("type") type: String?,
        @Field("title") title: String?,
        @Field("remark") remark: String?,
        @Field("version") version: Int = appVersionCode
    ): Observable<ApiResult<Any?>>
}